package com.hongxun.project.assets.iCablePit.service;

import java.util.List;
import java.util.UUID;

import com.hongxun.common.utils.bean.BeanUtils;
import com.hongxun.project.assets.iBoxes.domain.IBoxes;
import com.hongxun.project.assets.pBoxes.domain.PBoxes;
import com.hongxun.project.assets.pCablePit.domain.PCablePit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.iCablePit.mapper.ICablePitMapper;
import com.hongxun.project.assets.iCablePit.domain.ICablePit;
import com.hongxun.project.assets.iCablePit.service.IICablePitService;
import com.hongxun.common.utils.text.Convert;

/**
 * 电缆井 服务层实现
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class ICablePitServiceImpl implements IICablePitService 
{
	@Autowired
	private ICablePitMapper iCablePitMapper;

	/**
     * 查询电缆井信息
     * 
     * @param id 电缆井ID
     * @return 电缆井信息
     */
    @Override
	public ICablePit selectICablePitById(String id)
	{
	    return iCablePitMapper.selectICablePitById(id);
	}
	
	/**
     * 查询电缆井列表
     * 
     * @param iCablePit 电缆井信息
     * @return 电缆井集合
     */
	@Override
	public List<ICablePit> selectICablePitList(ICablePit iCablePit)
	{
	    return iCablePitMapper.selectICablePitList(iCablePit);
	}
	
    /**
     * 新增电缆井
     * 
     * @param iCablePit 电缆井信息
     * @return 结果
     */
	@Override
	public int insertICablePit(ICablePit iCablePit)
	{
		iCablePit.setId(UUID.randomUUID().toString());
	    return iCablePitMapper.insertICablePit(iCablePit);
	}
	
	/**
     * 修改电缆井
     * 
     * @param iCablePit 电缆井信息
     * @return 结果
     */
	@Override
	public int updateICablePit(ICablePit iCablePit)
	{
	    return iCablePitMapper.updateICablePit(iCablePit);
	}

	/**
     * 删除电缆井对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteICablePitByIds(String ids)
	{
		return iCablePitMapper.deleteICablePitByIds(Convert.toStrArray(ids));
	}


	public void file(List<PCablePit> pCablePitList) {
		for (PCablePit p : pCablePitList) {
			if (p.getDatastate().equals("删除")) {
				deleteICablePitByIds(p.getId());
			} else {
				ICablePit i = new ICablePit();
				BeanUtils.copyBeanProp(i, p);
				if (selectICablePitById(p.getId()) != null) {
					updateICablePit(i);
				} else {
					iCablePitMapper.insertICablePit(i);
				}
			}
		}
	}

}
